﻿using System;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Text;

class ExecBat
{
    public static System.Diagnostics.Process CreateShellExProcess(string cmd, string args, string workingDir = "")
    {
        var pStartInfo = new System.Diagnostics.ProcessStartInfo(cmd);
        pStartInfo.Arguments = args;
        pStartInfo.CreateNoWindow = false;
        pStartInfo.UseShellExecute = true;
        pStartInfo.RedirectStandardError = false;
        pStartInfo.RedirectStandardInput = false;
        pStartInfo.RedirectStandardOutput = false;
        if (!string.IsNullOrEmpty(workingDir))
        {
            pStartInfo.WorkingDirectory = workingDir;
        }

        return System.Diagnostics.Process.Start(pStartInfo);
    }

    public static void RunBat(string batfile, string args, string workingDir = "")
    {
        var path = workingDir.Replace("\\", "/");
        if (!System.IO.File.Exists(path))
        {
            Debug.Log("bat文件不存在：" + path);
            return;
        }
        else
        {
            var p = CreateShellExProcess(batfile, args, path);
            p.Close();
        }
    }
}
